#!/bin/bash
# 安装依赖
apt update && apt install curl wget unzip -y

# 下载并安装 sing-box
curl -Ls https://github.com/SagerNet/sing-box/releases/latest/download/sing-box-linux-amd64.zip -o sing-box.zip
unzip -o sing-box.zip -d /usr/local/bin/
chmod +x /usr/local/bin/sing-box

# 创建配置目录
mkdir -p /etc/sing-box/
cp config.json /etc/sing-box/config.json

# 创建 systemd 启动服务
cat <<EOF > /etc/systemd/system/sing-box.service
[Unit]
Description=Sing-box Service
After=network.target

[Service]
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/config.json
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reexec
systemctl daemon-reload
systemctl enable sing-box
systemctl restart sing-box

echo "sing-box 启动成功！"
